/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.UnsupportedEncodingException;

/**
 * <p>Project: javaseapp - Test
 * <p>Powered by webrx On 2021-08-16 10:17:54
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Test {
    public static void main(String[] args) {
        String str = "中";
        char x = '中';
        char c = 97;
        byte[] bytes = null;
        byte[] bytes1 = null;
        byte[] bytec = null;
        try {
            bytes = str.getBytes("utf-8");
            bytes1 = charToByte(x);
            bytec = charToByte(c);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        System.out.println("bytes 大小：" + bytes.length);
        System.out.println("bytes1大小：" + bytes1.length);
        System.out.println("bytec大小：" + bytec.length);
    }

    public static byte[] charToByte(char c) {
        byte[] b = new byte[2];
        b[0] = (byte) ((c & 0xFF00) >> 8);
        b[1] = (byte) (c & 0xFF);
        return b;
    }
}
